//
//  LoginvView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/12.
//

import SwiftUI

//中间弹窗通用试图
struct PopupCenterView<Content: View>: View {
    var title:String = ""
    var noBg = false
    var edgeinsets : EdgeInsets? = nil
    let dismiss: () -> Void
    @ViewBuilder var content: () -> Content
    
    var body: some View {
        VStack(spacing: 0) {
            ZStack(alignment:.top) {
                HStack{
                    Spacer()
                    Image(.appIconClose)
                        .resizable()
                        .padding(3)
                        .frame(width: 24,height: 24)
                        .onTapGesture {
                            dismiss()
                        }
                }
                Text(title).font(.system(size: 18))
                    .bold()
                    .foregroundStyle(.bgNormalText)
                    .padding(.vertical,10)
            }
            content()
        }.padding(getEdgeInsets())
        // 内层：45度渐变背景
            .background(
                LinearGradient(
                    gradient: Gradient(colors: [ themeManager.themeColor.opacity(0.15), .bgDialog, .bgDialog]),
                    startPoint: .topTrailing,
                    endPoint: .bottomLeading
                )
            )
        // 外层：
            .background(noBg ? Color.clear : .bgDialog)
            .cornerRadius(20)
            .edgesIgnoringSafeArea(.all)
            .frame(width: 320)
            .padding(.vertical, 50)
    }
    
    func getEdgeInsets() -> EdgeInsets {
        return edgeinsets ?? EdgeInsets(top: 10, leading: 10, bottom: 20, trailing: 10)
    }
}

#Preview {
    PopupCenterView(title: "温馨提示",dismiss:{}){}
}
